package com.bbx.taxi.client.widget.textView;

import com.bbx.androidapi.util.DensityUtil;
import com.bbx.taxi.client.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;

/**  
 * 主要用于斜体染色
 */
public class RotateTextView extends TextView{
	private int background=0;
	private Context context;

	public RotateTextView(Context context) {
		super(context, null);
		this.context=context;
	}

	public RotateTextView(Context context, AttributeSet attrs) {
		super(context, attrs, android.R.attr.textViewStyle);
		this.context=context;
		this.setGravity(Gravity.CENTER_HORIZONTAL);
		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.RotateTextView);
		background = a.getColor(R.styleable.RotateTextView_Rotatebackground,
				0);
		a.recycle();	
	}
	public void setBackground(int background){
		this.background=background;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
	}

	@Override
	protected void onDraw(Canvas canvas) {
		canvas.save();
		canvas.translate(getCompoundPaddingLeft(), getExtendedPaddingTop());
		Paint p=new Paint();
		p.setColor(background);
		Rect r=new Rect(0,getPaddingTop(),this.getWidth(),getPaddingTop()+(int)getTextSize()+7);
		canvas.drawRect(r,p);
//		canvas.rotate(mDegrees, this.getWidth() / 2f, this.getHeight() / 2f);
		super.onDraw(canvas);
		canvas.restore();
	}
	
}
